package com.qf.web;

import com.qf.pojo.Student;
import com.qf.service.StudentService;
import com.qf.service.impl.StudentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @date 2022/3/30
 * @desc   修改 学生信息  先根据 学生id 查询出来 要修改的数据   回显到修改的 表单页面
 */
@WebServlet("/studentUpdate")
public class StudentUpdateServlet  extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //获取  修改的学生的  id
        String id = req.getParameter("id");   // 从业务  和  技术 两个角度 去写注释

        StudentService studentService = new StudentServiceImpl();

        Student student = studentService.findStudentById(Integer.parseInt(id));

        req.setAttribute("student",student);

        req.getRequestDispatcher("/studentUpdate.jsp").forward(req,resp);
    }
}
